		TITLE	IMPNAME - Copyright (C) 1994 SLR Systems

		INCLUDE	MACROS
		INCLUDE	SEGMSYMS

if	fg_segm

		PUBLIC	IMPNAME_INSTALL,IMPMOD_INSTALL


		.DATA

		EXTERNDEF	SYMBOL_TEXT:BYTE

		EXTERNDEF	SYMBOL_LENGTH:DWORD,IMPMOD_HASH:DWORD,IMP_ORDNUM:DWORD,IMPMOD_HASH_TABLE_PTR:DWORD
		EXTERNDEF	FIRST_IMPMOD_GINDEX:DWORD,LAST_IMPMOD_GINDEX:DWORD,N_IMPMODS:DWORD

		EXTERNDEF	IMPNAME_GARRAY:STD_PTR_S,IMPMOD_GARRAY:STD_PTR_S,IMPNAME_STUFF:ALLOCS_STRUCT


		.CODE	PASS1_TEXT

		EXTERNDEF	COMMON_INST_INIT:PROC,IMPNAME_POOL_GET:PROC,IMPMOD_POOL_GET:PROC


IMPNAME_INIT	PROC
		;
		;
		;
		MOV	EAX,OFF IMPNAME_STUFF
		CALL	COMMON_INST_INIT

		MOV	EBX,IMPNAME_STUFF.ALLO_HASH_TABLE_PTR
		JMP	II_1

IMPNAME_INIT	ENDP


IMPNAME_INSTALL PROC
		;
		;EDX IS HASH VALUE, CONVERT IT
		;
		;RETURN EAX IS LOGICAL, EDX PHYS
		;
		;DESTROYS ES,DS,DI,SI,DX,CX
		;
		PUSH	EBX
		MOV	EAX,EDX

		MOV	EBX,IMP_ORDNUM
		XOR	EDX,EDX

		XOR	EAX,EBX			;HINT VALUE FOR PE
		MOV	EBX,IMPNAME_STUFF.ALLO_HASH_TABLE_PTR

		HASHDIV	IMPNAME_STUFF.ALLO_HASH	;DX IS HASH VALUE

		TEST	EBX,EBX
		JZ	IMPNAME_INIT
II_1::
		PUSHM	EDI,ESI

		MOV	EAX,DPTR [EBX+EDX*4]
		LEA	EBX,[EBX+EDX*4 - IMPNAME_STRUCT._IMP_NEXT_HASH_GINDEX]
NAME_NEXT:
		TEST	EAX,EAX
		JZ	DO_INSTALL

		MOV	EDX,EAX
		CONVERT	EBX,EAX,IMPNAME_GARRAY
		ASSUME	EBX:PTR IMPNAME_STRUCT
		;
		;PROBABLE MATCH, NEED COMPARE...
		;
		MOV	ECX,SYMBOL_LENGTH
		MOV	EDI,OFF SYMBOL_TEXT

		SHR	ECX,2
		LEA	ESI,[EBX]._IMP_TEXT

		INC	ECX

		REPE	CMPSD

		MOV	EAX,[EBX]._IMP_NEXT_HASH_GINDEX
		JNZ	NAME_NEXT

		MOV	ECX,IMP_ORDNUM
		MOV	EDI,[EBX]._IMP_HINT

		CMP	EDI,ECX
		JNZ	NAME_NEXT

		POPM	ESI,EDI

		MOV	ECX,EBX
		POP	EBX

		MOV	EAX,EDX			;AX IS SYMBOL GINDEX, DS:BX IS PHYS

		RET

DO_INSTALL:
		;
		;DS:BX GETS POINTER...
		;
		MOV	EAX,SYMBOL_LENGTH
		MOV	ESI,EBX

		ADD	EAX,SIZE IMPNAME_STRUCT-3		;
		CALL	IMPNAME_POOL_GET			;ES:DI IS PHYS, AX LOG

		MOV	EBX,EAX
		MOV	EDI,EAX

		INSTALL_POINTER_GINDEX	IMPNAME_GARRAY

		MOV	[ESI].IMPNAME_STRUCT._IMP_NEXT_HASH_GINDEX,EAX
		MOV	EDX,EAX

		MOV	ECX,IMPNAME_STRUCT._IMP_TEXT/4
		XOR	EAX,EAX

		REP	STOSD

		MOV	ECX,SYMBOL_LENGTH
		MOV	ESI,OFF SYMBOL_TEXT

		MOV	[EBX]._IMP_LENGTH,ECX
		ADD	ECX,4

		SHR	ECX,2
		MOV	EAX,EDX

		OPTI_MOVSD

		MOV	ECX,EBX
		POPM	ESI,EDI,EBX

		RET

IMPNAME_INSTALL ENDP


IMPMOD_INIT	PROC
		;
		;
		;
		PUSH	EAX
		MOV	EAX,OFF IMPNAME_STUFF

		CALL	COMMON_INST_INIT

		POP	EDX

IMPMOD_INIT	ENDP


IMPMOD_INSTALL PROC
		;
		;DX IS HASH VALUE, CONVERT IT
		;ES MUST BE DGROUP
		;
		;RETURN AX:BX IS LOGICAL, DX PHYS
		;
		;DESTROYS ES,DS,DI,SI,DX,CX
		;
		MOV	EAX,EDX
		MOV	EDX,IMPNAME_STUFF.ALLO_HASH_TABLE_PTR

		TEST	EDX,EDX
		JZ	IMPMOD_INIT

		XOR	EDX,EDX
		PUSH	EBX

		MOV	EBX,IMPMOD_HASH_TABLE_PTR

		HASHDIV	IMPMOD_HASH		;DX IS HASH VALUE

		PUSHM	EDI,ESI

		MOV	EAX,DPTR [EBX+EDX*4]
		LEA	EBX,[EBX+EDX*4 - IMPMOD_STRUCT._IMPM_NEXT_HASH_GINDEX]
NAME_NEXT:
		TEST	EAX,EAX
		JZ	DO_INSTALL

		MOV	EDX,EAX
		CONVERT	EBX,EAX,IMPMOD_GARRAY
		ASSUME	EBX:PTR IMPMOD_STRUCT
		;
		;PROBABLE MATCH, NEED COMPARE...
		;
		MOV	ECX,SYMBOL_LENGTH
		MOV	EDI,OFF SYMBOL_TEXT

		SHR	ECX,2
		LEA	ESI,[EBX]._IMPM_TEXT

		INC	ECX
		MOV	EAX,[EBX]._IMPM_NEXT_HASH_GINDEX

		REPE	CMPSD

		MOV	ECX,EBX
		JNZ	NAME_NEXT

		POPM	ESI,EDI

		POP	EBX
		MOV	EAX,EDX			;AX IS SYMBOL GINDEX, DS:BX IS PHYS

		RET

DO_INSTALL:
		;
		;DS:BX GETS POINTER...
		;
		MOV	EAX,SYMBOL_LENGTH
		MOV	ESI,EBX

		ADD	EAX,SIZE IMPMOD_STRUCT-3		;
		CALL	IMPMOD_POOL_GET				;ES:DI IS PHYS, AX LOG

		MOV	EDX,LAST_IMPMOD_GINDEX
		MOV	EBX,EAX

		MOV	EDI,EAX
		INSTALL_POINTER_GINDEX	IMPMOD_GARRAY
		MOV	[ESI].IMPMOD_STRUCT._IMPM_NEXT_HASH_GINDEX,EAX

		TEST	EDX,EDX
		JZ	FIRST

		CONVERT	EDX,EDX,IMPMOD_GARRAY
		ASSUME	EDX:PTR IMPMOD_STRUCT

		MOV	[EDX]._IMPM_NEXT_GINDEX,EAX
FIRST_RET:
		MOV	LAST_IMPMOD_GINDEX,EAX

		INC	N_IMPMODS
		MOV	EDX,EAX

		MOV	ECX,IMPMOD_STRUCT._IMPM_TEXT/4
		XOR	EAX,EAX

		REP	STOSD

		MOV	EAX,N_IMPMODS
		MOV	ECX,SYMBOL_LENGTH

		MOV	[EBX]._IMPM_NUMBER,EAX
		MOV	ESI,OFF SYMBOL_TEXT

		MOV	[EBX]._IMPM_LENGTH,ECX
		ADD	ECX,4

		SHR	ECX,2
		MOV	EAX,EDX

		OPTI_MOVSD

		MOV	ECX,EBX
		POPM	ESI,EDI,EBX
	
		RET

FIRST:
		MOV	FIRST_IMPMOD_GINDEX,EAX
		JMP	FIRST_RET

IMPMOD_INSTALL ENDP

endif

		END

